home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / VideoToolboxSources / MacMemory.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-15  |  1.0 KB  |  39 lines  |  [TEXT/MMCC]

  1. /* 
  2. MacMemory.c
  3.  
  4. This is meant to be used in association with MacMemory.h, which redefines the
  5. Standard C memory allocation functions to be implemented directly as calls to
  6. the Macintosh Memory Manager. So don't write programs that explicitly call
  7. "MacRealloc". This is for portable C programs that call "realloc", but which
  8. will be compiled to use MacRealloc instead, for best performance on the Mac.
  9.  
  10. You use MacMemory.h by adding the line
  11. #include "MacMemory.h"
  12. either to your THINK/CodeWarrior C project prefix or to some header file that you 
  13. include in all your files.
  14.  
  15. HISTORY:
  16. 10/25/94 dgp deleted MacMemset() because it's no longer needed. CodeWarrior 4.5 works fine.
  17. */
  18. #include "MacMemory.h"
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <Memory.h>
  23.  
  24. void *MacRealloc(void *oldPtr,size_t size)
  25. {
  26.     void *newPtr;
  27.     
  28.     if(oldPtr==NULL)return NewPtr(size);
  29.     SetPtrSize(oldPtr,size);
  30.     if(MemError()){
  31.         newPtr=NewPtr(size);
  32.         if(newPtr==NULL)return newPtr;
  33.         memcpy(newPtr,oldPtr,size);
  34.         DisposPtr(oldPtr);
  35.     }else newPtr=oldPtr;
  36.     return newPtr;
  37. }
  38.  
  39.